// 设置一个想到达的时间日期
var countDownDate = new Date("Jan 5, 2022 15:30:30").getTime();
// 每隔一秒更新一下
var timer = setInterval(function () {
  // 得到现在的具体时间
  var now = new Date().getTime();
  var distance = countDownDate - now; //相差的时间总数
  // 分别获取days hours minutes seconds 数值
  var days = Math.floor(distance / (1000 * 60 * 60 * 24));
  var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
  var seconds = Math.floor((distance % (1000 * 60)) / 1000);
  // 更新显示区域
  document.getElementById("demo").innerHTML = days + "d " + hours + "h " +
    minutes + "m " + seconds + "s ";
  // 如果到达设定的数值，清空定时器，并且显示区域EXPIRED 
  if (distance < 0) {
    clearInterval(timer);
    document.getElementById("demo").innerHTML = "EXPIRED";
  }
}, 1000);